﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class msg
    {
        public static dynamic getMsgList(int start, int limit, string username)
        {
            var sql = new Sql.SqlDataContext();
            var total = sql.Message.Count(row => row.to.ToLower() == username.ToLower());
            var result = from m in sql.Message
                         from u in sql.User
                         where m.to.ToLower() == username.ToLower() && u.username == m.@from
                         orderby m.mid descending
                         select new
                         {
                             m.mid,
                             m.title,
                             u.username,
                             u.nickname,
                             time = m.time.toTimeString(),
                             m.read
                         };
            return new
            {
                success = true,
                total,
                result
            };
        }
    }
}